package com.aiobc.business.appInfo.controller;

import com.aiobc.business.appInfo.domain.AppInfo;
import com.aiobc.business.appInfo.service.IAppInfoService;
import com.aiobc.common.core.web.controller.BaseController;
import com.aiobc.common.core.web.domain.AjaxResult;
import com.aiobc.common.core.web.page.TableDataInfo;
import com.aiobc.common.log.annotation.Log;
import com.aiobc.common.log.enums.BusinessType;
import com.aiobc.common.security.annotation.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * APP申请信息Controller
 *
 * @author ruoyi
 * @date 2021-10-20
 */
@RestController
@RequestMapping("/info")
@Api(value = "app信息", tags = "app信息")
public class AppInfoController extends BaseController {
    @Autowired
    private IAppInfoService appInfoService;

    /**
     * 查询上架APP信息列表
     *
     * @param appInf
     * @param sort   1代表按照时间最新排序 2代表按照评分高到低排序 3代表按下载量高到低排序
     * @return
     */
    @ApiOperation("app信息-查询上架APP信息列表")
    @GetMapping("/list")
    public TableDataInfo list(AppInfo appInf, Integer sort) {
        startPage();
        List<AppInfo> list = appInfoService.selectAppInfoList(appInf, sort);
        return getDataTable(list);
    }

    /**
     * 获取APP申请信息详细信息
     */
    @ApiOperation("app信息-取APP申请信息详细信息")
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") String dataId) {
        return AjaxResult.success(appInfoService.selectAppInfoByDataId(dataId));
    }

    /**
     * 新增APP申请信息
     */
    @ApiOperation("app信息-新增APP申请信息")
    @Log(title = "APP申请信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppInfo appInf) {
        return toAjax(appInfoService.save(appInf));
    }

    /**
     * 修改APP申请信息
     */
    @ApiOperation("app信息-修改APP信息")
    @Log(title = "APP申请信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppInfo appInf) {
        return toAjax(appInfoService.updateAppInfo(appInf));
    }

    /**
     * 删除APP申请信息
     */
    @ApiOperation("app信息-删除APP申请信息")
    @PreAuthorize(hasPermi = "system:info:remove")
    @Log(title = "APP申请信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable String[] dataIds) {
        return toAjax(appInfoService.deleteAppInfoByDataIds(dataIds));
    }
}
